package com.sam.designpattern.command.mainborad;

/**
 * @Author: Sam
 * @Date: 2022-08-26 15:43
 * @Description: 命令模式客户端
 */
public class Client {

    public static void main(String[] args) {
        //1：把命令和真正的实现组合起来，相当于在组装机器
        //把机箱上的按钮的连接线插接到主板上
        MainBoardApi mainBoard = new GigaMainBoard();
        //创建开机机器的命令
        OpenCommand openCommand = new OpenCommand(mainBoard);
        //创建重启机器的命令
        ResetCommand resetCommand = new ResetCommand(mainBoard);

        //2：为机箱上的按钮设置对应的命令，让按钮知道该干什么
        Box box = new Box();
        //正确配置 正常开机重启命令
        box.setOpenCommand(openCommand);
        box.setResetCommand(resetCommand);

        System.out.println("--------------正确配置下--------------");
        System.out.println(">>>按下开机按钮<<<");
        box.openButtonPressed();
        System.out.println(">>>按下重启按钮<<<");
        box.resetButtonPressed();

        System.out.println();

        //错误配置 颠倒开机与重启命令  补偿undo操作原理
        box.setOpenCommand(resetCommand);
        box.setResetCommand(openCommand);
        System.out.println("--------------错误配置下--------------");
        System.out.println(">>>按下开机按钮<<<");
        box.openButtonPressed();
        System.out.println(">>>按下重启按钮<<<");
        box.resetButtonPressed();

    }
}
